home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / BUTTONGA.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  8KB  |  241 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Definition of class TButtonGadget.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_BUTTONGA_H)
  10. #define OWL_BUTTONGA_H
  11.  
  12. #if !defined(OWL_GADGET_H)
  13. # include <owl/gadget.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace OWL {
  18. #endif
  19.  
  20. // Generic definitions/compiler options (eg. alignment) preceeding the 
  21. // definition of classes
  22. #include <services/preclass.h>
  23.  
  24. class _OWLCLASS TCelArray;
  25.  
  26. //
  27. // class TButtonGadget
  28. // ~~~~~ ~~~~~~~~~~~~~
  29. // Buttons begin highlighting and do a capture when pressed (the mouse down
  30. // occurs). they cancel highlighting when the mouse exits, but begin
  31. // highlighting again when the mouse re-enters. when the mouse goes up the
  32. // capture is released
  33. //
  34. // There are two basic type of buttons: commands and settings (attribute
  35. // buttons). Settings can be exclusive (like a radio button) or non-exclusive
  36. // (like a check box), or SemiExclusive where they act like both
  37. //
  38. // There are three normal button states: up, down, and indeterminate. in
  39. // addition the button can be highlighted (pressed) in all three states
  40. //
  41. // Commands can only be in the "up" state. Settings can be in all three states
  42. //
  43. class _OWLCLASS TButtonGadget : public TGadget {
  44.   public:
  45.     enum TType {   // Basic type of this button
  46.       Command,       // Single shot, sends command on press
  47.       Exclusive,     // Sticks down when pressed, pops out neighbors
  48.       NonExclusive,  // Toggles state when pressed, ignores neighbors
  49.       SemiExclusive, // Same as exclusive, plus pops up if pressed when down
  50.       RepeatCmd,     // Auto-repeating command 
  51.     };
  52.  
  53.     enum TState {  // Current state of this button
  54.       Up,            // Button is up, i.e. unchecked
  55.       Down,          // Button is down, i.e. checked
  56.       Indeterminate, // Button is neither checked nor unchecked
  57.     };
  58.  
  59.     enum TShadowStyle {  // Bottom & right side shadow width for old UI style
  60.       SingleShadow = 1,
  61.       DoubleShadow = 2,
  62.     };
  63.  
  64.     TButtonGadget(TResId glyphResIdOrIndex,
  65.                   int    id,
  66.                   TType  type = Command,
  67.                   bool   enabled = false, // initial state before cmd enabling
  68.                   TState state = Up,
  69.                   bool   sharedGlyph = false);
  70.    ~TButtonGadget();
  71.  
  72.     // Some accessors
  73.     //
  74.     void          SetButtonState(TState newState);
  75.     TState        GetButtonState() const;
  76.  
  77.     TType         GetButtonType() const;
  78.     void          GetDesiredSize(TSize& size);
  79.     void          SetBounds(const TRect& r);
  80.  
  81.     // A few button style options. These styles may be ignores on some
  82.     // UI platforms
  83.     //
  84.     bool          GetNotchCorners() const;
  85.     void          SetNotchCorners(bool notchCorners=true);
  86.  
  87.     TShadowStyle  GetShadowStyle() const;
  88.     void          SetShadowStyle(TShadowStyle style=DoubleShadow);
  89.  
  90.     bool          GetAntialiasEdges() const;
  91.     void          SetAntialiasEdges(bool anti=true);
  92.  
  93.     // Override and initiate a WM_COMMAND_ENABLE message
  94.     //
  95.     void          CommandEnable();
  96.     void          SysColorChange();
  97.  
  98.   protected:
  99.     // Some accessors are protected
  100.     //
  101.     void          SetButtonType(TType newType);
  102.  
  103.     // Override basic TGadget member functions
  104.     //
  105.     void          Paint(TDC& dc);
  106.     void          Invalidate();
  107.  
  108.     // Override TGadget member functions and respond to user fiddling with the
  109.     // button by self-sending button protocol messages
  110.     //
  111.     void          LButtonDown(uint modKeys, TPoint& p);
  112.     void          MouseMove(uint modKeys, TPoint& p);
  113.     void          MouseEnter(uint modKeys, TPoint& p);
  114.     void          MouseLeave(uint modKeys, TPoint& p);
  115.     void          LButtonUp(uint modKeys, TPoint& p);
  116.  
  117.     // Glyph types and construction functions
  118.     //
  119.     enum {
  120.       //CelMask,
  121.       CelNormal,    // Normal state
  122.       CelDisabled,  // Disabled (grayed)
  123.       CelIndeterm,  // Indeterminate-neither normal nor down
  124.       CelDown,      // Down or checked
  125.       CelPressed,   // Optional pressed glyph
  126.       CelsTotal,
  127.     };
  128.  
  129.     virtual TDib* GetGlyphDib();
  130.     virtual void  ReleaseGlyphDib(TDib* glyph);
  131.     virtual void  BuildCelArray();
  132.  
  133.     // button protocol
  134.     // ~~~~~~ ~~~~~~~~
  135.  
  136.     // Invoked by mouse-down & mouse enter events. sets member data "Pressed"
  137.     // to true and highlights the button
  138.     //
  139.     virtual void  BeginPressed(TPoint& p);
  140.  
  141.     // Invoked by mouse exit events. sets member data "Pressed" to false and
  142.     // paints the button in its current state
  143.     //
  144.     virtual void  CancelPressed(TPoint& p);
  145.  
  146.     // The action method called on a completed 'click', generates WM_COMMAND
  147.     //
  148.     virtual void  Activate(TPoint& p);
  149.  
  150.   protected_data:
  151.     TResId        ResId;            // Bmp res id if glyph is owned here
  152.     TCelArray*    CelArray;         // CelArray used to cache glyph states
  153.  
  154.     TPoint        BitmapOrigin;     // Where glyph sits on button
  155.     TState        State         :4; // Current state of button
  156.     TType         Type          :4; // Type of this button
  157.     TShadowStyle  ShadowStyle   :4; // Shadow style, may be ignored w/ 3dUI
  158.     bool          NotchCorners  :1; // Notch (round) corners? ignored w/ 3dUI
  159.     bool          Pressed       :1; // Is this button current pressed by user
  160.     bool          AntialiasEdges:1; // Should border edges be antialiased?
  161.     bool          SharingGlyph;     // Should the button share glyphs with its
  162.                                     // gadget window?
  163.     int           GlyphIndex;       // Base index for our glyph bitmap
  164.  
  165.   private:
  166.     int           GlyphCount;       // How many glyphs are we using (1,3,4,5)
  167.  
  168.   private:
  169.     void          CheckExclusively();
  170. };
  171.  
  172. // Generic definitions/compiler options (eg. alignment) following the 
  173. // definition of classes
  174. #include <services/posclass.h>
  175.  
  176. #if defined(BI_NAMESPACE)
  177. } // namespace OWL
  178. #endif
  179.  
  180. //----------------------------------------------------------------------------
  181. // Inline implementations
  182. //
  183.  
  184. //
  185. // Return the current state of the button.
  186. //
  187. inline TButtonGadget::TState TButtonGadget::GetButtonState() const {
  188.   return State;
  189. }
  190.  
  191. //
  192. // Return the type of the button.
  193. //
  194. inline TButtonGadget::TType TButtonGadget::GetButtonType() const {
  195.   return Type;
  196. }
  197.  
  198. //
  199. // Returns true if the button has rounded corners.
  200. //
  201. inline bool TButtonGadget::GetNotchCorners() const {
  202.   return NotchCorners;
  203. }
  204.  
  205. //
  206. // Sets the flag for rounded corners on the button.
  207. //
  208. inline void TButtonGadget::SetNotchCorners(bool notchCorners) {
  209.   NotchCorners = notchCorners;
  210. }
  211.  
  212. //
  213. // Return the current shadow style of the button.
  214. //
  215. inline TButtonGadget::TShadowStyle TButtonGadget::GetShadowStyle() const {
  216.   return ShadowStyle;
  217. }
  218.  
  219. //
  220. // Returns true if the border edges are antialiased.
  221. //
  222. inline bool TButtonGadget::GetAntialiasEdges() const {
  223.   return AntialiasEdges;
  224. }
  225.  
  226. //
  227. // Sets the flag for antialiased borders.
  228. //
  229. inline void TButtonGadget::SetAntialiasEdges(bool anti) {
  230.   AntialiasEdges=anti;
  231. }
  232.  
  233. //
  234. // Sets the type of the button.
  235. //
  236. inline void TButtonGadget::SetButtonType(TType newType) {
  237.   Type = newType;
  238. }
  239.  
  240. #endif  // OWL_BUTTONGA_H
  241.